package com.woniuxy.email.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//主题模式配置
@Configuration
public class TopicModelConfig {

    //添加一个交换机
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("topic.exchange");
    }

    //添加两个队列
    @Bean
    public Queue topicQueue1() {
        return new Queue("topic.queue1");
    }

    @Bean
    public Queue topicQueue2() {
        return new Queue("topic.queue2");
    }

    //绑定队列和交换机
    @Bean
    public Binding topicBinding1(Queue topicQueue1, TopicExchange topicExchange) {
        //路由键使用通配符
        return BindingBuilder.bind(topicQueue1).to(topicExchange).with("china.#");
    }

    @Bean
    public Binding topicBinding2(Queue topicQueue2, TopicExchange topicExchange) {
        //路由键使用通配符
        return BindingBuilder.bind(topicQueue2).to(topicExchange).with("#.news");
    }
}